package jfuzzyprincepless.zarchive.negotiation.protocols;

import jfuzzyprincepless.zarchive.algorithm.structure.ICommandConstruction;
import jfuzzyprincepless.negotiation.INegotiation;
import jfuzzyprincepless.negotiation.INegotiationContext;
import jfuzzyprincepless.zarchive.negotiation.protocols.ObjFilter;
import jfuzzyprincepless.zarchive.negotiation.protocols.TypeFilter;

public class FrontNegotiationProtocol
	implements INegotiationProtocol__Q_del
{
	private ChaitNegotiationProtocol chainProtocol =
		new ChaitNegotiationProtocol();

	@Override
	public INegotiation createNegotiation(
		ICommandConstruction construction,
		INegotiationContext context
	) {
		return chainProtocol.createNegotiation(construction, context);
	}

	public void specifyForType(
		Class<? extends ICommandConstruction> clazz,
		INegotiationProtocol__Q_del subProtocol,
		boolean wholeHierarhy
	) {
		chainProtocol.getStagesList().add(
			0,
			new FilteringNegotiationProtocol(
				new TypeFilter(clazz, wholeHierarhy),
				subProtocol
			)
		);
	}

	public void specifyForType(
		Class<? extends ICommandConstruction> clazz,
		INegotiationProtocol__Q_del subProtocol
	) {
		specifyForType(clazz, subProtocol, false);
	}

	public void specifyForObject(
		ICommandConstruction construction,
		INegotiationProtocol__Q_del subProtocol
	) {
		chainProtocol.getStagesList().add(
			0,
			new FilteringNegotiationProtocol(
				new ObjFilter(construction),
				subProtocol
			)
		);
	}
}
